/* 
 * File:   Texture.h
 * Author: artem
 *
 * Created on November 19, 2011, 1:56 PM
 */

#ifndef TEXTURE_H
#define TEXTURE_H

#include "GL/opengl.h"

#include "Common.h"

#include "Resource/Image.h"
#include "Resource/FontDesc.h"

namespace Render
{
	class Texture
	{
	public:
		Texture(): m_width(0), m_height(0)
		{
			glGenTextures(1, &m_handle);
		}
		
		Texture(const char *name): m_width(0), m_height(0)
		{
			ASSERT(name);
			glGenTextures(1, &m_handle);
			
			if (Resource::Image *image = Resource::loadImage(name))
			{
				if (!setData(image))
					LOG_ERROR("Can't load image '%s'\n", name);
				delete image;
			}
		}
		
		~Texture()
		{
			glDeleteTextures(1, &m_handle);
		}
		
		GLuint getHandle() const { return m_handle; }
		
		uint32_t getWidth() const { return m_width; }
		uint32_t getHeight() const { return m_height; }
		
		bool setData(const Resource::Image *image);
		bool setData(const Resource::FontDesc *font);
		
	protected:
		GLuint   m_handle;
		uint32_t m_width;
		uint32_t m_height;
	};
}

#endif /* TEXTURE_H */
